<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>socket</title>
    <script type="text/javascript" src="jquery.js"></script>
</head>
<body>
    <div id="div1">
        <div style="width: 200px; height: 200px; background: lightcoral;" ></div>	
    </div>
    <br>
    <div>
        <!-- <a href="http://localhost:8082/add/send/key1" >""</a> -->
        <button id="button">点击向后端发送token</button>
    </div>
    <script>
        var url="ws://localhost:8082/"
        var key="key1"
        //前端发送websocket连接请求
        var webSocketUrl = url+"webSocket/"+key;
        var websocket = new WebSocket( webSocketUrl );
        //只要后端通过websocket向此连接发消息就会触发onmessage事件
        websocket.onmessage = function(event){
            var msg = event.data;
            console.log("msg");
            if(msg=="token"){ //验证后端发过来token令牌是否正确
                $("#div1").html("<label style='font-size:20px; color:green'>订单支付完成！</label>");
            }
        }
        $("#button").click(function() {
                $.ajax({
					url: "http://localhost:8082/add/send/key1", // key1是向后端发送的想访问的session长链接的key
				});
			});
    </script>
</body>
</html>